﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="CustomerOrders.ascx.cs" Inherits="WebUI.Controls.CustomerOrders" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>

<script type="text/javascript">
    var <%=ClientID %>clickOnCheckbox;
    var <%=ClientID %>selectedRow = null;       
    var <%=ClientID %>selectedCheckbox = null; 
    var <%=ClientID %>selectedID = null; 
    var <%=ClientID %>selectedClass = null; 
    
    function resetGridSelection<%=ClientID %>(){
        try{
            <%=ClientID %>selectedRow = null; 
            if(<%=ClientID %>selectedCheckbox != null)
                <%=ClientID %>selectedCheckbox.checked = false;      
            <%=ClientID %>selectedCheckbox = null; 
            <%=ClientID %>selectedID = null; 
            <%=ClientID %>selectedClass = null; 
        }
        catch(ex){
        }
    }
    
    function clickOnCheckBox<%=ClientID %>(cb){
        <%=ClientID %>clickOnCheckbox = true;
    }
    
     function onItemClick<%=ClientID %>(sender)
    {
        var hidSelectedID = document.getElementById("<%= hidSelectedID.ClientID %>");
        if(<%=ClientID %>clickOnCheckbox){
            <%=ClientID %>clickOnCheckbox = false;
            return;
        }

        if(<%=ClientID %>selectedRow == null){
            <%=ClientID %>selectedRow = document.getElementById("<%=ClientID %>" + "_row_" + hidSelectedID.value);
        }
        
        if(<%=ClientID %>selectedRow != null){
            if(<%=ClientID %>selectedRow.className)
                <%=ClientID %>selectedRow.className = <%=ClientID %>selectedRow.getAttribute("orgclass");
            else
                <%=ClientID %>selectedRow.setAttribute("class", <%=ClientID %>selectedClass);
            if(<%=ClientID %>selectedCheckbox != null)
                <%=ClientID %>selectedCheckbox.checked = false;
            else{
                var chks = <%=ClientID %>selectedRow.getElementsByTagName("input");
                 for(var i = 0; i < chks.length; i++){
                    if(chks[i].type == "checkbox" && chks[i].id.indexOf("cbSelect") >= 0){
                        chks[i].checked = false;
                        break;
                    }
                }
            }
        }
        
        if(sender.className){
            sender.className = "CustomGridSelectedItem";
        }
        else{
            <%=ClientID %>selectedClass = sender.getAttribute("class");
            sender.setAttribute("class", "CustomGridSelectedItem");
        }
        <%=ClientID %>selectedRow = sender;
        
        var inputs = sender.getElementsByTagName("input");
        for(var i = 0; i < inputs.length; i++){
            if(inputs[i].type == "checkbox" && inputs[i].id.indexOf("cbSelect") >= 0){
                <%=ClientID %>selectedCheckbox = inputs[i];
                inputs[i].checked = true;
                break;
            }
        }

        hidSelectedID.value = <%=ClientID %>selectedRow.getAttribute("ItemID");
    }
    
    function selectAll<%=ClientID %>(cbAll){
        var grid = document.getElementById("<%=grid.ClientID %>");
        var inputs = grid.getElementsByTagName("input");
        for(var i = 0; i < inputs.length; i++){
            if(inputs[i].type == "checkbox"){
                inputs[i].checked = cbAll.checked;
            }
        }
    }
    
    function getSelectedItemID<%=ClientID %>(){
        if(document.getElementById("<%= hidSelectedID.ClientID %>").value == "")
            return null;
        return document.getElementById("<%= hidSelectedID.ClientID %>").value;
    }

    function showPrintDlg(key) {
        var returnValue = window.showModalDialog(key, '', 'dialogWidth=800px;dialogHeight=600px;resizable=yes;help=no;unadorned=yes;');
    }

    var stopRowClickEvent<%=ClientID %> = false;

    function onInvoiceNo_click(invoiceID){  
        var hidInvoiceID = document.getElementById("<%= hidInvoiceID.ClientID %>");
        hidInvoiceID.value = invoiceID;
        stopRowClickEvent<%=ClientID %> = false;
        if(invoiceID == "")
            return false;
        stopRowClickEvent<%=ClientID %> = true;
        return true;
    }

     function HasCheckedItems<%=ClientID %>(){
        var grid = document.getElementById("<%=grid.ClientID %>");
        var inputs = grid.getElementsByTagName("input");
        var ok = false;
        for(var i = 0; i < inputs.length; i++){
            if(inputs[i].type == "checkbox"  && inputs[i].id.indexOf("cbSelect") >= 0 && inputs[i].checked == true ){
                ok = true;
            }
        }
        return ok;
    }
</script>

<asp:DataGrid ID="grid" runat="server" AllowPaging="true" AllowSorting="true" GridLines="None" CssClass="customGrid"
    AutoGenerateColumns="false" EmptyDataText="No record to display" ItemStyle-Wrap="true" CellPadding="1" CellSpacing="1"
    OnSortCommand="grid_OnSortCommand" OnItemCreated="grid_OnItemCreated" OnItemDataBound="grid_OnItemDataBound"
    OnPageIndexChanged="grid_OnPageIndexChanged" AllowCustomPaging="true" UseAccessibleHeader="true" DataKeyField="ID">
    <PagerStyle Mode="NumericPages" PageButtonCount="10" />
    <Columns>
       <asp:TemplateColumn ItemStyle-Width="20px" HeaderStyle-Width="20px" ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center">
            <HeaderTemplate><asp:CheckBox ID="cbSelectAll" runat="server" /></HeaderTemplate>
            <ItemTemplate>
                <asp:CheckBox ID="cbSelect" runat="server" ItemID='<%# Eval("ID") %>' />
            </ItemTemplate>
        </asp:TemplateColumn>
        <%--start modify here--%>
        <asp:BoundColumn ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left" ItemStyle-Width="150px" DataField="ID" SortExpression="ID" HeaderText="ID" Visible="false"></asp:BoundColumn>
        <asp:BoundColumn HeaderStyle-HorizontalAlign="Left" ItemStyle-Width="40px" DataField="OrderNo" SortExpression="OrderNo" HeaderText="No."></asp:BoundColumn>
        
        <asp:TemplateColumn ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left"
            ItemStyle-Width="100px" SortExpression="CreatedDate" HeaderText="Submitted Date" Visible="true">
            <ItemTemplate>
                <asp:Label ID="lblDate" runat="server" Text='<%# ((DateTime)Eval("CreatedDate")).ToString(POSSystem.BLL.SystemVariables.SysVars.DateFormat) %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateColumn>
        
        <asp:BoundColumn HeaderStyle-HorizontalAlign="Left" ItemStyle-Width="120px" DataField="CustomerName" SortExpression="CustomerName" HeaderText="Customer"></asp:BoundColumn>
        <asp:BoundColumn HeaderStyle-HorizontalAlign="Left" ItemStyle-Width="120px" DataField="ShipAddress" SortExpression="ShipAddress" HeaderText="Ship To"></asp:BoundColumn>
        
        <asp:TemplateColumn ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left"
            ItemStyle-Width="100px" SortExpression="PreferredShipDate" HeaderText="Preferred Ship Date" Visible="true">
            <ItemTemplate>
                <asp:Label ID="lblPreferredShipDate" runat="server" Text='<%# Eval("PreferredShipDate") != DBNull.Value ? ((DateTime)Eval("PreferredShipDate")).ToString(POSSystem.BLL.SystemVariables.SysVars.DateFormat) : "" %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateColumn>
        <%--<asp:BoundColumn HeaderStyle-HorizontalAlign="Left" ItemStyle-Width="120px" DataField="PreferredShipDate" SortExpression="PreferredShipDate" HeaderText="Preferred Ship Date"></asp:BoundColumn>--%>
        
        <asp:TemplateColumn ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left"
            ItemStyle-Width="100px" SortExpression="ShipDate" HeaderText="Real Ship Date" Visible="true">
            <ItemTemplate>
                <asp:Label ID="lblShipDate" runat="server" Text='<%# Eval("ShipDate") != DBNull.Value ? ((DateTime)Eval("ShipDate")).ToString(POSSystem.BLL.SystemVariables.SysVars.DateFormat) : "" %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateColumn>
        <%--<asp:BoundColumn HeaderStyle-HorizontalAlign="Left" ItemStyle-Width="120px" DataField="ShipDate" SortExpression="ShipDate" HeaderText="Real Ship Date"></asp:BoundColumn>--%>
        
        <asp:TemplateColumn ItemStyle-HorizontalAlign="Left" HeaderStyle-HorizontalAlign="Left"
            ItemStyle-Width="100px" SortExpression="PaymentMethod" HeaderText="Payment Method" Visible="true">
            <ItemTemplate>
                <asp:Label ID="lblPaymentMethod" runat="server" Text='<%# Eval("PaymentMethod") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateColumn>

        <asp:BoundColumn ItemStyle-HorizontalAlign="Right" HeaderStyle-HorizontalAlign="Left" ItemStyle-Width="60px" DataField="TotalAmount"  HeaderText="Total"></asp:BoundColumn>
        <asp:BoundColumn HeaderStyle-HorizontalAlign="Left" ItemStyle-Width="150px" DataField="Note" SortExpression="Note" HeaderText="Note"></asp:BoundColumn>
        <asp:TemplateColumn ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center" ItemStyle-Width="20px" HeaderStyle-Width="20px" HeaderText="Status">
            <ItemTemplate>
                <asp:LinkButton ID="btnStatus" runat="server" OnClick="btnPrint_OnClick" OnClientClick='<%# "return onInvoiceNo_click(\"" + (Eval("InvoiceID") == DBNull.Value ? "" : Eval("InvoiceID")) + "\");" %>'>
                    <asp:Image ToolTip='<%# Eval("StatusName") %>' ImageUrl='<%# GetStatusImageLink((int)Eval("StatusID")) %>' runat="server" ID="imgDelete" />
                </asp:LinkButton>
            </ItemTemplate>
        </asp:TemplateColumn>
        <%--end modify here--%>
    </Columns>
</asp:DataGrid>
<asp:HiddenField ID="hidSelectedID" runat="server" />
<asp:HiddenField ID="hidInvoiceID" runat="server" />
<%--<asp:Image ImageUrl="~/Images/npending.gif" runat="server" />
<asp:Label runat="server" class="labelMessage" Text="Pending"></asp:Label>&nbsp;
<asp:Image ID="Image1" ImageUrl="~/Images/nInvoiceCreated.png" runat="server" />
<asp:Label ID="Label1" runat="server" class="labelMessage" Text="Invoice Created"></asp:Label>&nbsp;
<asp:Image ID="Image2" ImageUrl="~/Images/nshipped.gif" runat="server" />
<asp:Label ID="Label2" runat="server" class="labelMessage" Text="Shipped"></asp:Label>&nbsp;
<asp:Image ID="Image3" ImageUrl="~/Images/nrejected.gif" runat="server" />
<asp:Label ID="Label3" runat="server" class="labelMessage" Text="Rejected"></asp:Label>--%>